﻿
@{
    ViewBag.Title = "Content";
    Layout = "~/Views/Shared/CommonView.cshtml";
    One_day.Models.Table table = ViewBag.lst;
    

}
@section css{
    <style>
        .plussub {
            width: 120px;
            height: 32px;
            border: 1px solid #ccc;
            background: #fff;
            margin: 0 auto;
        }

            .plussub span {
                width: 30px;
                height: 30px;
                float: left;
                text-align: center;
                line-height: 30px;
                cursor: pointer;
            }

            .plussub .sub {
                border-right: 1px solid #ccc;
            }

            .plussub .plus {
                border-left: 1px solid #ccc;
            }

            .plussub input[type="text"] {
                border: none;
                height: 30px;
                width: 56px;
                text-align: center;
                float: left;
                line-height: 30px;
            }
    </style>
    }
<div>
    <a style="position:fixed;top:0px;margin:5px;text-align:center" href="~/Yichen/List">
        <img src="~/Upload/back.png" style="width:40px;height:40px;" />
    </a>
    <div><img src="@table.PicUrl" style="width:100%;"/></div>
    <h2>名字：@table.ProductName</h2>
    <h4>价钱：@table.Price</h4>
    <h4>已卖：@table.SelledAmount</h4>
    
    <form action="~/Yichen/ShopStore" style="text-align:center;">
        <ul style="list-style:none;">
            <li style="float:left;">
                <div class="plussub" style="position:relative;left:0px;">
                    <span onclick="sub(1)" class="sub">-</span>
                    <input class="yzquantity1" onblur="yzquantity(1)" type="text" value="1" name="num">
                    <span onclick="plus(1)" class="plus">+</span>
                </div>
            </li>
            <li style="float:left;">
                <label style="margin-right:20px;">（剩余：@table.StockAmount )</label>
                <button type="submit" style="position:relative;left:0px;" class="btn btn-primar">加入到购物篮</button>
            </li>
        </ul>
        

        <input type="text" name="ProductId" value="@table.Id" style="visibility:hidden" />
        
    </form>
</div>
@section js{
    <script>
        /*增加或删除数量*/
        function sub(psid) {
            var yzquantity = $(".yzquantity" + psid).val();
            if (yzquantity > 0) {
                if (yzquantity == 1) {
                    //alert("已到达最小数量！");
                    $(".yzquantity").val(1);
                    return;
                }
                yzquantity--;
                $(".yzquantity" + psid).val(yzquantity);
            } else {
                alert("请输入有效数量！");
            }
        }

        function plus(psid) {
            var yzquantity = $(".yzquantity" + psid).val();
            if(yzquantity>=@table.StockAmount){
                $(".yzquantity").val(@table.StockAmount);  
                return;
            }
            if (yzquantity > 0) {
                yzquantity++;
                $(".yzquantity" + psid).val(yzquantity);
            }
            else {
                    alert("请输入有效数量！");
            }
        }

        function yzquantity(psid) {
            var yzquantity = $(".yzquantity" + psid).val();
            var reg = /^[0-9]*$/;
            reg.test(yzquantity);
            if (reg.test(yzquantity) == false) {
                alert("请输入有效数量！");
                $(".yzquantity" + psid).val(yzquantity);
            }
        }
    </script>
    }

